package com.android.djlmapp.dialog;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.djlmapp.R;
import com.android.djlmapp.model.my.ZhuanZhangInfo;

import java.text.DecimalFormat;

import razerdp.basepopup.BasePopupWindow;

public class ZhuanchuPopup extends BasePopupWindow {
    public static final String TAG = "djlm-my: ";
    public static ZhuanZhangInfo.DataBean item;
    public String order_sn,accAccount, accName, accTime, accState, accMoney, accRelMoney, note;

    public ZhuanchuPopup(Context context) {
        super(context);
    }

    public static void setInfo(ZhuanZhangInfo.DataBean mItem) {
        item = mItem;
        Log.i(TAG, "mItem: "+item.toString());
    }

    // 必须实现，这里返回您的contentView
    // 为了让库更加准确的做出适配，强烈建议使用createPopupById()进行inflate
    @Override
    public View onCreateContentView() {
        order_sn = item.getTrade_id();
        accAccount = item.getOpen_bank() +"("+item.getBank_num()+")";
        accName = item.getOpen_name();
        accTime = item.getAdddate() + " " + item.getAddtime();

        String money = new DecimalFormat("#").format(Double.parseDouble(item.getMoney()));
        accMoney = money;
        accRelMoney = ""+(Integer.parseInt(money) - 3);
        note = item.getNote();


        if ("1".equals(item.getIs_ok())) {
            accState = "转出成功";
        } else {
            accState = "转出失败";
        }

        Log.i(TAG, "order_sn: "+order_sn);
        View view = createPopupById(R.layout.dialog_dz);

        TextView title = view.findViewById(R.id.dz_title);
        title.setText("转账详情");

        TextView dz_name = view.findViewById(R.id.dz_name);
        dz_name.setText("转账流水号:");
        TextView dz_name_v = view.findViewById(R.id.dz_name_v);
        dz_name_v.setText(order_sn);

        TextView dz_money = view.findViewById(R.id.dz_money);
        dz_money.setText("收款人账号:");
        TextView dz_money_v = view.findViewById(R.id.dz_money_v);
        dz_money_v.setText(accAccount);

        TextView dz_time = view.findViewById(R.id.dz_time);
        dz_time.setText("收款人:");
        TextView dz_time_v = view.findViewById(R.id.dz_time_v);
        dz_time_v.setText(accName);

        TextView dz_result = view.findViewById(R.id.dz_result);
        dz_result.setText("转账时间:");
        TextView dz_result_v = view.findViewById(R.id.dz_result_v);
        dz_result_v.setText(accTime);

        LinearLayout layout5 = view.findViewById(R.id.dz_5);
        layout5.setVisibility(View.VISIBLE);
        TextView dz_result5 = view.findViewById(R.id.dz_result5);
        dz_result5.setText("转账状态:");
        TextView dz_result5_v = view.findViewById(R.id.dz_result5_v);
        dz_result5_v.setText(accState);

        LinearLayout layout6 = view.findViewById(R.id.dz_6);
        layout6.setVisibility(View.VISIBLE);
        TextView dz_result6 = view.findViewById(R.id.dz_result6);
        dz_result6.setText("转账金额:");
        TextView dz_result6_v = view.findViewById(R.id.dz_result6_v);
        dz_result6_v.setText(accMoney);

        LinearLayout layout7 = view.findViewById(R.id.dz_7);
        layout7.setVisibility(View.VISIBLE);
        TextView dz_result7 = view.findViewById(R.id.dz_result7);
        dz_result7.setText("预计到账:");
        TextView dz_result7_v = view.findViewById(R.id.dz_result7_v);
        dz_result7_v.setText(accRelMoney);

        LinearLayout layout8 = view.findViewById(R.id.dz_8);
        layout8.setVisibility(View.VISIBLE);
        TextView dz_result8 = view.findViewById(R.id.dz_result8);
        dz_result8.setText("备注信息:");
        TextView dz_result8_v = view.findViewById(R.id.dz_result8_v);
        dz_result8_v.setText(note);

        return view;
    }

    // 以下为可选代码（非必须实现）
    // 返回作用于PopupWindow的show和dismiss动画，本库提供了默认的几款动画，这里可以自由实现
    @Override
    protected Animation onCreateShowAnimation() {
        return getDefaultScaleAnimation(true);
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return getDefaultScaleAnimation(false);
    }
}
